﻿// -----------------------------------------------------------------------
// <copyright file="SampleTaskContext.cs" company="The Usual Dosage">
// © 2013 by Matthew M. Martin
// </copyright>
// -----------------------------------------------------------------------

namespace Cadence.NET.Examples
{
    using Cadence.NET.BaseClasses;
    using Cadence.NET.Interfaces;
    using System;

    /// <summary>
    /// An example of a Cadence TaskContext.
    /// </summary>
    public class SampleTaskContext : ITaskContext
    {

        /// <summary>
        /// Gets or sets the error context.
        /// </summary>
        /// <value>
        /// The error context.
        /// </value>
        public System.Exception ErrorContext { get; set; }

        /// <summary>
        /// Gets or sets the task started notification message.
        /// </summary>
        /// <value>
        /// The task started notification message.
        /// </value>
        public string TaskStartedNotificationMessage { get; set; }

        /// <summary>
        /// Gets or sets the task completed notification message.
        /// </summary>
        /// <value>
        /// The task completed notification message.
        /// </value>
        public string TaskCompletedNotificationMessage { get; set; }

        /// <summary>
        /// Gets or sets the duration of the run.
        /// </summary>
        /// <value>
        /// The duration of the run.
        /// </value>
        public System.TimeSpan? RunDuration
        {
            get
            {
                if (LastRunStarted.HasValue && LastRunCompleted.HasValue)
                {
                    return LastRunCompleted.Value.Subtract(LastRunStarted.Value);
                }
                else
                {
                    return (TimeSpan?)null;
                }
            }
        }

        /// <summary>
        /// Gets or sets the last run started.
        /// </summary>
        /// <value>
        /// The last run started.
        /// </value>
        public System.DateTime? LastRunStarted { get; set; }

        /// <summary>
        /// Gets or sets the last run completed.
        /// </summary>
        /// <value>
        /// The last run completed.
        /// </value>
        public System.DateTime? LastRunCompleted { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is error.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is error; otherwise, <c>false</c>.
        /// </value>
        public bool IsError { get; set; }
    }
}
